package com.examlpe.cels;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import com.examlpe.cels.entity.Vocabulary;
import com.examlpe.cels.entity.Word;
import com.examlpe.cels.mapper.VocabularyMapper;
import com.examlpe.cels.mapper.WordMapper;

public class testq1 {

private SqlSessionFactory ssf;
	
	@Before
	public void setUp() throws IOException {
		
		String resource = "MybatisConfig.xml";
		InputStream input = Resources.getResourceAsStream(resource);
		
		ssf = new SqlSessionFactoryBuilder().build(input);
		
		
	}
	
//	@Test
//	public void testAllWord() {
//		SqlSession ss = ssf.openSession();
//		
//		//Mapper接口对象
//		WordMapper wm = ss.getMapper(WordMapper.class);
//		
//		List<Word> words = wm.findAllWord();
//		for(Word word:words) {
//			System.out.println(word);
//		}
//		ss.close();
//	}

	
//	@Test
//	public void testAllVocabulary() {
//		SqlSession ss = ssf.openSession();
//		
//		//Mapper接口对象
//		VocabularyMapper vm = ss.getMapper(VocabularyMapper.class);
//		List<Vocabulary> vocabularys = vm.findAllVocabulary();
//		for(Vocabulary vocabulary:vocabularys) {
//			System.out.println(vocabulary);
//		}
//		ss.close();
//	}
	
	@Test
	public void testAllVocabulary() {
		SqlSession ss = ssf.openSession();
		
		//Mapper接口对象
		VocabularyMapper vm = ss.getMapper(VocabularyMapper.class);
		List<Vocabulary> vocabularys = vm.findAllVocabulary();
		for(Vocabulary vocabulary:vocabularys) {
			System.out.println(vocabulary);
		}
		ss.close();
	}
}
